//Collections查找方法
package daily.may0517;

import java.util.ArrayList;
import java.util.Collections;

public class CollectionsSearchTest {
    public static void main(String[] args) {
        //创建集合并添加元素
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list, 4, 16, 9, 1, 49, 81, 64, 25, 36, 81);

        //max方法和min方法
        System.out.println("集合中最大元素" + Collections.max(list));//81
        System.out.println("集合中最小元素" + Collections.min(list));//1

        //sort方法排序
        Collections.sort(list);
        System.out.println(list);//[1, 4, 9, 16, 25, 36, 49, 64, 81, 81]

        //binarySearch方法查找元素
        System.out.println("元素36的下标：" + Collections.binarySearch(list, 36));//5

        //replaceAll方法用999替换集合中所有的81
        Collections.replaceAll(list, 81, 999);
        System.out.println(list);//[1, 4, 9, 16, 25, 36, 49, 64, 999, 999]

    }
}
